package nin.ja;

/*
 * NOTE: need to be pooling Component objects higher up the hierarchy!
 * Should be creating GameObjects and their needed components
 * in the same place
 */
public class ComponentManager {
	private static final int DEFAULT_SIZE = 64;
	private Component components[];
	private int size;
	
	public ComponentManager(){
		components = new Component[DEFAULT_SIZE];
		for(int i = 0; i < components.length; ++i){
			components[i] = null;
		}
		size = 0;
	}
	
	public void addComponent(Component c){
		if(size < components.length){
			for(int i = 0; i < components.length; ++i){
				if(components[i] == null){
					components[i] = c;
					break;
				}
			}
			++size;
		}
		else{
			// enter here if not enough room for more components
		}
	}
	
	public void deleteComponent(Component c){
		for(int i = 0; i < components.length; ++i){
			if(components[i] == c){
				components[i] = null;
				break;
			}
		}
	}
	
	public void update(float delta){
		for(int i = 0; i < components.length; ++i){
			if(components[i] != null){
				components[i].update(delta);
			}
		}
	}
	
	public int numberOfComponents(){
		return size;
	}
	
	

}
